#include <iostream>

void* strcpy(void* str1,const void* str2){
    char* dst=(char*)str1;
    char* ori=(char*)str2;
    while(*ori!=0){
        *dst=*ori;
        dst++;
        ori++;
    }
    *dst=0;
    return dst;
}

using namespace std;

class String{
private:
    char* str;
    size_t size;
public:
    //String();
    String(const char* ori="");
    String(const String& s);
    size_t length();
    String& operator=(const String& s);
    String& operator+=(const String& s);
    friend ostream& operator<<(ostream& out,const String& s);
    char operator[](size_t n);
    size_t find(char c, size_t pos = 0) const;
    ~String();
};

String::String(const char* ori){
    size=0;
    for(const char*i=ori;*i!=0;i++)
        size++;
    str = new char[size+ 1];
	strcpy(str, ori);
}

String::String(const String& s){
    size=s.size;
    str = new char[size+ 1];
	strcpy(str, s.str);
}

size_t String::length(){
    return size;
}

String& String::operator=(const String& s){
    size=s.size;
    delete [] str;
    str = new char[size+ 1];
	strcpy(str, s.str);
    return *this;
}

String& String::operator+=(const String& s){
    size_t tsize=size+s.size;
    char* tstr = new char[tsize+ 1];
	strcpy(tstr, str);
    delete []str;
    strcpy(tstr+size,s.str);
    str=tstr;
    size=tsize;
    return *this;
}

char String::operator[](size_t n){
    if(n<=size)
        return str[n];
    else
        return '\n';
}

ostream& operator<<(ostream& out,const String& s){
    out<<s.str;
    return out;
}

size_t String::find(char c, size_t pos) const
{
	if(pos > size)
        return -1;
	for (size_t i = pos; i < size; i++)
	{
		if (str[i] == c)
		{
			return i;
		}
	}
	return -1;
}

String::~String(){
    delete[] str;
}

int main(){
    String a;
    String b="Hello";
    String c="World";
    
    cout<<"a:"<<a<<"\tb:"<<b<<"\tc:"<<c<<endl;
    cout<<"查找o的位置:"<<b.find('o',0)<<endl;
    a=b;
    a+=c;
    cout<<"拼接a=b+c:"<< a<<endl;
    cout<<"截取a[4]:"<<a[4]<<endl;
    return 0;
}